package net.jescort.lucene.runnable;

import net.jescort.lucene.impl.IndexManagerImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Created by IntelliJ IDEA.
 * User: admin@gelif.net
 * Date: 11-8-25
 * Time: 下午5:12
 */
public class WriteToIndexRunnable extends IndexRunnable
{

    public WriteToIndexRunnable(IndexManagerImpl mgr)
    {
        super(mgr);
    }

    private static Log logger = LogFactory.getFactory().getInstance(WriteToIndexRunnable.class);

    public void doRun()
    {
        try
        {
            manager.getReadWriteLock().writeLock().lock();
            logger.debug("Starting search index operation");
            doRun();
            logger.debug("Search index operation complete");

        } catch (Exception e)
        {
            logger.error("Error acquiring write lock on index", e);

        } finally
        {
            manager.getReadWriteLock().writeLock().unlock();
        }
        manager.resetSharedReader();
    }
}
